package com.linln.admin.system.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;

import com.linln.admin.system.domain.User;

/**
 * @author 小懒虫
 * @date 2018/8/14
 */
public interface UserRepository extends BaseRepository<User, Long> {
	/**
	 * 根据用户名查询用户数据
	 *
	 * @param username 用户名
	 * @return 用户数据
	 */
	User findByUsernameAndStatusIn(String username, Byte[] status);

	/**
	 * 查找ID列表且状态正常
	 *
	 * @param ids ID列表
	 * @param status 状态
	 */
	List<User> findByIdInAndStatus(List<Long> ids, Byte status);

	@Query(value = "select distinct u.* from sys_user u inner join sys_user_role r on u.id=r.user_id where if(?1 != null, u.dept_id = ?1, 1=1) and r.role_id = ?2", nativeQuery = true)
	// @Query("select distinct u from User u inner join u.roles r where u.deptId = ?1 and r.id = ?2")
	List<User> findByDeptAndRole(Long deptId, Long roleId);

}
